<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//"https://api.vk.com/method/database.getCities?country_id="+coun+"&q="+city+"&need_all=0&v=5.16&count=1000

$term = trim($_POST['value']);

//$term = $_POST[term];
$countr = $_POST['countr'];
  $url = 'https://api.vk.com/method/database.getCities?country_id=' . urlencode($countr) . '&q=' . urlencode($term) . '&need_all=0&v=5.16&count=1000';

      // обращаемся к API и декодируем результат
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_REFERER, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     $translate = curl_exec($ch);
     curl_close($ch);
     $json = json_decode($translate, true);
     
   
		foreach ($json['response']['items'] as $item)
		{
        $found[] = array(
			
			"value" => $item['title'],
			);
		}
   
// JSON encode the array for return
echo json_encode($found);
         